home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2517 / 2517.xpi / content / googlepedia.js < prev    next >
Text File  |  2009-08-15  |  21KB  |  333 lines

  1. // Googlepedia
  2. // 
  3. // Copyright (c) 2006-2009, James Hall
  4. // Feel free to share, modify, sell etc...
  5.  
  6. var googleUrl = window.location.href.match(/http:\/\/(.*?)\//);
  7. googleUrl = 'http://'+googleUrl[1]+'/';
  8. var googleTld = window.location.href.match(/http:\/\/(.*?)\.google\.(.*?)\/(.*?)/);
  9. var wikipediaLanguage;
  10.  
  11. if (GM_getValue('language') == '') {
  12.     var googleLanguage = getQueryVariable('hl');
  13.     
  14.     if (googleLanguage == '') {
  15.         googleLanguage = 'en';
  16.     }
  17.     
  18.     // Wikipedia doesn't appear to have Traditional and Simplified versions
  19.     if (googleLanguage == 'zh-CN' || googleLanguage == 'zh-TW') {
  20.         googleLanguage = 'zh';
  21.     }
  22.     
  23.     if (googleLanguage == 'de-DE' || googleLanguage == 'de-AT' || googleLanguage == 'de-CH') {
  24.         googleLanguage = 'de';
  25.     }
  26.     
  27.     if (googleLanguage == 'pt-BR' || googleLanguage == 'pt-PT') {
  28.         googleLanguage = 'pt';
  29.     }
  30.     
  31.     wikipediaLanguage = googleLanguage;
  32. } else {
  33.     wikipediaLanguage = GM_getValue('language');
  34. }
  35.  
  36. var wikipediaUrl = 'http://' + wikipediaLanguage + '.wikipedia.org/' 
  37.  
  38. var Images = {
  39.     throbber: 'data:image/gif;base64,R0lGODlhEAAQAPMAAP%2F%2F%2F2Zm%2F4uL%2FtfX%2FpWV%2Fq6u%2FuPj%2Fra2%2FsfH%2Fuvr%2FszM%2FtjY%2FvHx%2Ftvb%2FgAAAAAAACH%2BFU1hZGUgYnkgQWpheExvYWQuaW5mbwAh%2BQQBAAAAACH5BAAKAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAAEPBDISau9dggxMBVBIHgTKJKSxpFGURgoUBBEEc913L6xlCCIRAxxOCCGRQRjsWBgfsGFQrGISamxZdMSAQAh%2BQQACgABACwAAAAAEAAQAAAEPhDIOYQYM2sRgtCTURQG54FSQRBFdaGAysKZSNJAgiAJLiGHA8IHAAqJOh5RwlgsGMSFQrGITqu%2B5nPJ7UYAACH5BAAKAAIALAAAAAAQABAAAAQ%2BEMhpSjEz60JI0VOCIAnnDYIwZMhxINUlBIHAukg215lIZiiVhLFYMECghUKxQGqUTGeGaJRar9isdst1RgAAIfkEAAoAAwAsAAAAABAAEAAABD4QyJkQSjNrdA7SE7MsDOcZRWFki6Is1VUQRMG6SzbXmUhmKBVoCBgIBANiRhAICJQTphMqMSKp2Kx2y91GAAAh%2BQQACgAEACwAAAAAEAAQAAAEPRDIydZiM%2Bul1NIgwHkJgiQhUF3IcSBp1r7xVJ51ZhSFkQMFAqHwCw5%2Fu15tIBAMfoJAQACVUnNM528biwAAIfkEAAoABQAsAAAAABAAEAAABDwQyEmrvdiytViei6IsnxSOJbB1qZQgSJIix4HM9V2%2B8WcUBUOqQCAUMAOBYEA0YgSBgOAXfEYFqeTSEgEAIfkEAAoABgAsAAAAABAAEAAABDwQyEmrvTjrzbufzLIw3KIoS3mmWzhKgyAMVIIgCSUEgUAhhwNCxxMYCgUDUEiJzQoEQsGGw0ClnGPSEgEAIfkEAAoABwAsAAAAABAAEAAABDsQyEmrvTjrzXsdgjBwQhAIpIluoOgZRWFQzLIwVEEQBbUoikVuV0ggEIlfkAKTIQ4HRO2GeUY5RqQlAgA7AAAAAAAAAAAA',
  40.     networkError: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAABGdBTUEAALGPC%2FxhBQAAAAlwSFlzAAALEgAACxIB0t1%2B%2FAAAAAd0SU1FB9YCERABCn8%2BTScAAAIVSURBVDjLjZNfSJNRGMZ%2FZ%2Fs%2BkmQDJ4RCG0s2QYpACFIyKxhi0ZV2N7sIBhldRKCRdGEM77oqI4QuVhdFwpC6CiRyoGt0I6sMDPozjakf%2Bg1pbc7NndPFYLXSj967w%2FPyvOf3nPcI9qjw2GgU6Me6JjQLsb8n0Ivf37qraBgG0anJQSsD%2FP5Wzgbv7KpNP7sJgKWBEAKArq6jgAIq57m590gpKwZWrPcf3OV81z6KwmDJrCe%2FtU02V6jp0f6TlY3NynS7pgOglPqNYMX69OoJ3A8jeNJrAGQcB5j1nay5wZ6sKjLOh1CE7kAAp9sNwObyModmZkiOjICnuTZEu93G2voP8lvb7P%2FykXPmJ7qvXEaZJuXFRaRSOBsa6AwGmX38CEfn8UiNwcLnVVCV6afeTXOstwe1vs7O6ipSSpSUlNJpbMUih0%2BfIfs2cUn7MxAzbVTNnBvfcXouoN8YRtd1hIBKm0IIgQyPob94XkEwDIOXT4ZrwnvlGUfpOgiBECClrL69EIJSJlMNcSI6NTn4d%2FoHG12YySSOgYvkEglkqYQsl5FSornd5F0u7MXSGw0YvH5tiEKhdkEyR9pZCIVo7%2BhANDVRTqeRgL25GVtLC9%2Fi8ZyEWxrAysrKvwvQ1kZDXx%2Fz0Shen496rxcF%2FDRNUvF4biefvzcAMREeG1VW%2F6Hua4rG1zHqUktZABvMl%2BH2AMQAfgGt5toAC2JPDAAAAABJRU5ErkJggg%3D%3D'
  41. }
  42.  
  43. function addGlobalStyle(css) {
  44.     var head, style;
  45.     head = document.getElementsByTagName('head')[0];
  46.     if (!head)
  47.     {
  48.         return;
  49.     }
  50.     style = document.createElement('style');
  51.     style.type = 'text/css';
  52.     style.innerHTML = css;
  53.     head.appendChild(style);
  54. }
  55.  
  56. // Thanks to Pete Freitag for this very useful function
  57. function getQueryVariable(variable) {
  58.     var query = window.location.search.substring(1);
  59.     var vars = query.split("&");
  60.     for (var i=0;i<vars.length;i++) {
  61.         var pair = vars[i].split("=");
  62.         if (pair[0] == variable) {
  63.             return pair[1];
  64.         }
  65.     }
  66.     return ''; 
  67. }
  68.  
  69. // Remove Google adwords
  70.  
  71. (function () {
  72.     // Thanks to Max Kueng (http://maxkueng.com/) for this next bit
  73.     /*var f = document.getElementsByTagName('font');
  74.     for (var i=0;i<f.length;i++) {
  75.         if (f[i].className == 'a') {
  76.             t = f[i].parentNode.parentNode.parentNode.parentNode.parentNode;
  77.             t.style.display = 'none';
  78.         }
  79.     }*/
  80.     
  81.     // New top Adword removal code
  82.     // Uses color to make it MUCH less likely a dom change will remove the
  83.     // wrong element
  84.     var d = document.getElementsByTagName('div');
  85.     for (var i=0;i<d.length;i++) {
  86.         if(d[i].id == 'tpa1') {
  87.             //alert(d[i].style.backgroundColor);
  88.         }
  89.         if (d[i].style.backgroundColor == 'rgb(229, 236, 249)' || d[i].style.backgroundColor ==    'rgb(255, 249, 221)') {
  90.             d[i].style.display = 'none';
  91.         }
  92.     }    
  93.     
  94.     // More adword removal...
  95.     var mbEnd = document.getElementById('mbEnd');
  96.     if(mbEnd != undefined) {
  97.         mbEnd.style.display = 'none';
  98.     }
  99.     /*
  100.     var tads = document.getElementById('tads');
  101.     if(tads != undefined) {
  102.         tads.style.display = 'none';
  103.     }*/    
  104.     
  105. }());
  106.  
  107. var allElements, thisElement, wikibox;
  108. allElements = document.getElementsByTagName('a');
  109. for (var i = 0; i < allElements.length; i++) {
  110.     thisElement = allElements[i];
  111.     if(thisElement.className == 'l') {
  112.         var firstLink = thisElement;
  113.         i = allElements.length;
  114.     }
  115. }
  116.  
  117. function retrieveURL(url) {
  118.     GM_xmlhttpRequest({
  119.         method: 'GET',
  120.         url: url,
  121.         headers: {
  122.             'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  123.             'Accept': 'application/atom+xml,application/xml,text/xml'
  124.         },
  125.         onload: function(responseDetails) {
  126.             articleLoaded = true;
  127.             wikibox.innerHTML = responseDetails.responseText;
  128.  
  129.             if(document.getElementById('content')) {
  130.                 wikibox.innerHTML = boxhtml + document.getElementById('content').innerHTML;
  131.                 if(getQueryVariable('anchor') != "") {
  132.                     document.location.href = document.location.href + '#' + getQueryVariable('anchor');
  133.                 }
  134.                 document.getElementById('hideLink').addEventListener("mousedown", function(e) {
  135.                     document.getElementById('showGooglepediaBox').style.display='block';
  136.                     document.getElementById('wikibox').style.display='none';
  137.                     GM_setValue('hidden', '1');
  138.                 }, false);                
  139.             } else {
  140.                 wikibox.innerHTML = getString('noArticleFound');
  141.             }
  142.             
  143.             var rewriteLinks = GM_getValue('rewrite_links');
  144.             var header = wikibox.getElementsByTagName('h1')[0];
  145.                 
  146.             header.innerHTML = header.innerHTML + ' <a class="linkBack" href="' + url.replace(/"/g, '%22') + '">(' + getString('viewOnWikipedia') + ')</a>';
  147.                 
  148.             var allLinks, allImages, thisElement;
  149.             allLinks = wikibox.getElementsByTagName('a');
  150.             for (var i = 0; i < allLinks.length; i++) {
  151.                 thisElement = allLinks[i];
  152.                 var thisHref = thisElement.href;
  153.                 if(thisHref.match('Image:')) {
  154.                     thisHref = thisHref.replace(/http:\/\/(.*).google.(.*)\/wiki\//,wikipediaUrl+"wiki/");
  155.                     //var urlSplit = thisHref.split('/');
  156.                     //thisHref = thisHref.replace(urlSplit[urlSplit.length - 1], '');
  157.                 } else if(thisHref.match('#')) {
  158.                     //http://www.google.com/
  159.                     if(thisHref.match(/http:\/\/(.*).google.(.*)\/wiki\//)) {
  160.                         //alert('yes');
  161.                         if(rewriteLinks) {
  162.                             thisHref = thisHref.replace(/http:\/\/(.*).google.(.*)\/wiki\/(.*)#(.*)/, googleUrl+"search?hl="+googleLanguage+"&wikititle=1&q=$3&anchor=$4");
  163.                         } else {
  164.                             thisHref = thisHref.replace(/http:\/\/(.*).google.(.*)\/wiki\//, wikipediaUrl+"wiki/");
  165.                         }
  166.                         // TODO: Make sure anchored links work when page title has more than one keyword
  167.                             
  168.                     }
  169.                     //Internal link
  170.                 } else if(thisHref.match('/w/index.php')) {
  171.                     thisHref = thisHref.replace(/http:\/\/(.*).google.(.*)\/w\//,wikipediaUrl+"w/")
  172.                 } else {
  173.                     if(rewriteLinks) {
  174.                         var originalHref = thisHref;
  175.                         var newHref = thisHref.replace(/http:\/\/(.*).google.(.*)\/wiki\//,googleUrl+"search?hl="+googleLanguage+"&wikititle=1&q=");
  176.                             
  177.                         if(originalHref != newHref) {
  178.                             newHref = newHref.replace(/_/g, ' ');
  179.                         }
  180.                             
  181.                         thisHref = newHref;
  182.                             
  183.                     } else {
  184.                         thisHref = thisHref.replace(/http:\/\/(.*).google.(.*)\/wiki\//, wikipediaUrl+"wiki/");
  185.                     }
  186.                 }
  187.                     
  188.                 thisElement.href = thisHref;
  189.             }
  190.                 
  191.             allImages = wikibox.getElementsByTagName('img');
  192.             for (var i = 0; i < allImages.length; i++) {
  193.                 thisElement = allImages[i]; 
  194.                 if(thisElement.src == googleUrl + 'skins-1.5/common/images/magnify-clip.png') {
  195.                     thisElement.src = wikipediaUrl + 'skins-1.5/common/images/magnify-clip.png'
  196.                 } else {
  197.                     // Direct links to full-sized images
  198.                     var realImage = thisElement.src;
  199.                     realImage = realImage.replace(/thumb\//, '');
  200.                     realImage = realImage.replace(/\/[^\/.]+$/, '');
  201.                     var imageSplit = realImage.split('/');
  202.                     realImage = realImage.replace('/' + imageSplit[imageSplit.length - 1], '');
  203.                     // That can be written nicer surely ;)
  204.                     if (realImage.indexOf('.jpg') != -1 || realImage.indexOf('.png') != -1 || realImage.indexOf('.gif') != -1 || realImage.indexOf('.svg') != -1) {
  205.                         thisElement.parentNode.href = realImage;
  206.                     } else {
  207.                         thisElement.parentNode.href = thisElement.src;
  208.                     }
  209.                     
  210.                 }
  211.                  
  212.             }                    
  213.                                 
  214.         }
  215.     });
  216. }
  217.  
  218.  
  219. addGlobalStyle('#wikibox { z-index: 999; background-color: #fff; overflow: hidden; position: relative; top: 20px;margin-right:11px;    }');
  220. addGlobalStyle('#showGooglepediaBox { z-index: 999; float: right; width: 50%; text-align: right; display:none; position: relative; top: 20px;    }');
  221.  
  222. var start = getQueryVariable('start');
  223. if(GM_getValue('hidden', '0')=='1' || (start != '' && start != '0')) {
  224.     addGlobalStyle('#showGooglepediaBox { display:block;font-size:13px !important}');
  225. }
  226.  
  227. addGlobalStyle('#hideLink { float: right; }');
  228. addGlobalStyle('.shrunk { float: right; width: 50%; border-left: 3px solid #efefef; padding-left: 10px; margin-left: 10px; margin-bottom: 32px; }');
  229. addGlobalStyle('.expanded { float: none; width: 100%; border: 0; padding: 0; border-bottom: 3px solid #efefef; padding-bottom: 10px; margin-bottom: 30px;}');
  230. addGlobalStyle('#throbber, #networkError { vertical-align:middle; padding-right: 10px; }');
  231. addGlobalStyle('#navbar { text-align: left; width: 50%;    } hr { width: 45% !important; } ');
  232.  
  233.  
  234. addGlobalStyle('#bodyContent a.external, #bodyContent a[href^="gopher://"] {-moz-background-clip:border;-moz-background-inline-policy:continuous;-moz-background-origin:padding;background:transparent url(http://en.wikipedia.org/skins-1.5/monobook/external.png) no-repeat scroll right center;padding-right:13px;}');
  235. // Wikipedia CSS
  236. //addGlobalStyle('.infobox{float:right;}#jump-to-nav{display:none;}#bc table,#bc td,#bc div,#bc nobr,#bc font,#bc input,#bc a{font-family:Arial, Helvetica, sans-serif !important;font-size:12px;font-weight:400;color:#000;cursor:default;line-height:1.6em;}#bc a{cursor:pointer;color:#003FBF !important;text-decoration:none;}#bc a:hover{text-decoration:underline;}#bc h1.firstHeading{font-size:260%;font-family:Arial, Helvetica, sans-serif;color:#000;margin:10px 0 2px;}#bc h3#siteSub{font-size:130%;color:#CCC;margin:0 0 20px;}#bc h1{font-size:200%;}#bc h4{font-size:150%;margin-bottom:0;#bch4a font-size:100%;}#bc .navcontent{display:block;}#bc #catlinks{border-top:1px solid #DDE5F9;border-left:1px solid #DDE5F9;border-right:1px solid #BCC2D0;border-bottom:1px solid #BCC2D0;background:url(../pix/mediabg.png) #FFF repeat-x top left;padding:2px 10px;}#bc #catlinks p{margin:0;}#toc{border:1px solid #DBDFE6;background-color:#F0F2F5;}#toctitle h2{font-size:140%;padding-left:10px;}#toctitle TD{padding-top:16px;}#tocinside TD{padding:10px 20px 20px;}div.thumb{border:1px solid #CCC;background-color:#F9F9F9;width:auto;margin:20px;padding:4px;}div.tright{clear:right;float:right;}.internal IMG{border:1px solid #CCC;}.thumbcaption{padding:6px 4px 4px;}.tocline{font-size:12pt;}.tocindent{padding-left:20px;}.toctext{padding-left:7px;}img,#bc a img{border:0;}#bc h2,#bc h2 a{font-size:150%;}');
  237. //addGlobalStyle('#bc table,#bc td,#bc div,#bc nobr,#bc font,#bc input,#bc a{font-family:Arial, Helvetica, sans-serif !important;font-size:10px;}IMG{border:1px solid #CCC;}.thumbcaption{padding:6px 4px 4px;}.tocline{font-size:12pt;}.tocindent{padding-left:20px;}.toctext{padding-left:7px;}img,#bc a img{border:0;}#bc h2,#bc h2 a{font-size:150%;}');
  238.  
  239. // Styles lovingly handpicked from the wikipedia site then compressed. Some heavy tweaking in places
  240. addGlobalStyle('h1.firstHeading{clear:both;}#wikibox img{border:0 !important}#wikibox,#wikibox ul{font-size:13px !important}.infobox{ border:1px solid #aaa; background-color:#f9f9f9; color:black; margin-bottom:0.5em; margin-left:1em; padding:0.2em; float:right; clear:right}.infobox td,.infobox th{ vertical-align:top}.infobox caption{ font-size:larger; margin-left:inherit}.infobox.bordered{ border-collapse:collapse}.infobox.bordered td,.infobox.bordered th{ border:1px solid #aaa}.infobox.bordered .borderless td,.infobox.bordered .borderless th{ border:0}.infobox.sisterproject{ width:20em; font-size:90%}.infobox.bordered .mergedtoprow td,.infobox.bordered .mergedtoprow th{ border:0; border-top:1px solid #aaa; border-right:1px solid #aaa}.infobox.bordered .mergedrow td,.infobox.bordered .mergedrow th{ border:0; border-right:1px solid #aaa}.infobox.geography{ border:1px solid #ccd2d9; text-align:left; border-collapse:collapse; line-height:1.2em; font-size:90%}.infobox.geography td,.infobox.geography th{ border-top:solid 1px #ccd2d9; padding:0.4em 0.2em 0.4em 0.8em}.infobox.geography .mergedtoprow td,.infobox.geography .mergedtoprow th{ border-top:solid 1px #ccd2d9; padding:0.4em 0.2em 0.2em 0.8em}.infobox.geography .mergedrow td,.infobox.geography .mergedrow th{ border:0; padding:0 0.2em 0.2em 0.8em}.infobox.geography .mergedbottomrow td,.infobox.geography .mergedbottomrow th{ border-top:0; border-bottom:solid 1px #ccd2d9; padding:0 0.2em 0.4em 0.8em}.infobox.geography .maptable td,.infobox.geography .maptable th{ border:0; padding:0 0 0 0}#toc a{text-decoration:none}#toc,.toc,.mw-warning{border:1px solid #aaa;background-color:#f9f9f9;padding:5px;font-size:95%}#toc h2,.toc h2{display:inline;border:none;padding:0;font-size:100%;font-weight:bold}#toc #toctitle,.toc #toctitle,#toc .toctitle,.toc .toctitle{text-align:center}#toc ul,.toc ul{list-style-type:none;list-style-image:none;margin-left:0;padding-left:0;text-align:left}#toc ul ul,.toc ul ul{margin:0 0 0 2em}#toc .toctoggle,.toc .toctoggle{font-size:94%}div.thumb{margin-bottom:.5em;border-style:solid;border-color:white;width:auto}div.thumb div{border:1px solid #ccc;padding:3px !important;background-color:#f9f9f9;font-size:94%;text-align:center;overflow:hidden}div.thumb div a img{border:1px solid #ccc}div.thumb div div.thumbcaption{border:none;text-align:left;line-height:1.4em;padding:.3em 0 .1em 0}div.magnify{float:right;border:none !important;background:none !important}div.magnify a,div.magnify img{display:block;border:none !important;background:none !important}div.tright{clear:right;float:right;border-width:.5em 0 .8em 1.4em;font-size:13px;text-decoration:none}div.tleft{float:left;margin-right:.5em;border-width:.5em 1.4em .8em 0}.hiddenStructure{display:none;speak:none}img.tex{vertical-align:middle}span.texhtml{font-family:serif}img{border:none;vertical-align:middle}p{margin:.4em 0 .5em 0;line-height:1.5em}p img{margin:0}hr{height:1px;color:#aaa;background-color:#aaa;border:0;margin:.2em 0 .2em 0}#wikibox h1,#wikibox h2,#wikibox h3,#wikibox h4,#wikibox h5,#wikibox h6{color:black;background:none;font-weight:normal;margin:0;padding-top:.5em;padding-bottom:.17em;border-bottom:1px solid #aaa}h1{font-size:188%}h2{font-size:150%}#wikibox    h3,#wikibox h4,#wikibox h5,#wikibox h6{border-bottom:none;font-weight:bold}#wikibox h3{font-size:132%}#wikibox h4{font-size:116%}#wikibox h5{font-size:100%}#wikibox h6{font-size:80%}#wikibox ul{line-height:1.5em;list-style-type:square;margin:.3em 0 0 1.5em;padding:0;list-style-image:url(bullet.gif)}#wikibox ol{line-height:1.5em;margin:.3em 0 0 3.2em;padding:0;list-style-image:none}#wikibox li{margin-bottom:.1em}#wikibox dt{font-weight:bold;margin-bottom:.1em}#wikibox dl{margin-top:.2em;margin-bottom:.5em}#wikibox dd{line-height:1.5em;margin-left:2em;margin-bottom:.1em}#wikibox #catlinks{border:1px solid #aaa;background-color:#f9f9f9;padding:5px;margin-top:1em;clear:both}#wikibox table.rimage{float:right;position:relative;margin-left:1em;margin-bottom:1em;text-align:center}#wikibox .toccolours{border:1px solid #aaa;background-color:#f9f9f9;padding:5px;font-size:95%}div.townBox{position:relative;float:right;background:white;margin-left:1em;border:1px solid gray;padding:.3em;width:200px;overflow:hidden;clear:right}div.townBox dl{padding:0;margin:0 0 .3em;font-size:96%}div.townBox dl dt{background:none;margin:.4em 0 0}div.townBox dl dd{margin:.1em 0 0 1.1em;background-color:#f3f3f3}#siteNotice div{text-align:center !important;font-size:100%}.references-small *{font-size:11px}.tright a{text-decoration:none;font-size:13px !important}#jump-to-nav{display:none}a.new,#quickbar a.new{color:#C20} #siteSub{ display:inline; font-size:92%; font-weight:normal} #siteNotice{font-size:14px !important} #siteSub{display:block;padding-top:4px;margin-bottom:15px}.editsection{display:none;}a.linkBack{font-size:0.4em;font-weight:normal;}');
  241. addGlobalStyle('ol.references li { list-style-type: decimal !important; } h3#siteSub { display:none; }#cnt {max-width:1000em !important;}');
  242.  
  243. wikibox = document.createElement('div');
  244. showGooglepediaBox = document.createElement('div'); 
  245.  
  246. var originalContent;
  247. var showGooglepedia;
  248.  
  249. var boxhtml = '<a id=\'expandLink\' href="#" onmousedown="document.getElementById(\'wikibox\').className=\'expanded\'; document.getElementById(\'shrinkLink\').style.display=\'inline\'; document.getElementById(\'expandLink\').style.display=\'none\'; return false;" style="float: left;">‹ ' + getString('expand') + '</a>'
  250.         + '<a id=\'shrinkLink\' href="#" onmousedown="document.getElementById(\'wikibox\').className=\'shrunk\'; document.getElementById(\'expandLink\').style.display=\'inline\'; document.getElementById(\'shrinkLink\').style.display=\'none\';    return false;" style="display:none; float: left;">' + getString('shrink') + ' ›</a>'
  251.         + '<a id=\'hideLink\' href="#" id="hideLink">' + getString('hide') + ' »</a>';
  252.  
  253. var showGooglepedia = '<a id="showLink" href="#">« Googlepedia</a>';
  254. var debugLink = '<a onclick="document.innerHTML = \'<text\'+\'area>\'+document.innerHTML+\'</text\'+\'area>\';">Debug</a>';
  255. var networkError = '<img id="networkError" src="'+Images.networkError+'" />' + getString('networkProblem');
  256. var results = document.getElementById('res');
  257.  
  258.  
  259.  
  260. window.initWikibox = function () {
  261.     var articleLoaded = false;
  262.  
  263.     if(getQueryVariable('wikititle') == '1') {
  264.         // For those queries when you don't feel so lucky[tm]
  265.         retrieveURL(wikipediaUrl+'wiki/'+getQueryVariable('q').replace(/%20/g, '_'));
  266.     } else {
  267.         // TODO: Make this a preference?
  268.         var noSpecialPages = true;
  269.         var url = '';
  270.         // Possible talk / special page fix
  271.         //google talk site:http://en.wikipedia.org/wiki -inurl:User: -inurl:Talk: -inurl:"User_talk:" -inurl:"Template:" -inurl:"Template_talk:" 
  272.         if(noSpecialPages) {
  273.             var specialPageRemove = '+-inurl:"User:"+-inurl:Talk:+-inurl:"User_talk:"+-inurl:"Template:"+-inurl:"Template_talk:"';
  274.             var url = googleUrl+'search?q='+getQueryVariable('q')+'+site:'+wikipediaUrl+'wiki' + specialPageRemove + '&btnI=I%27m+Feeling+Lucky';        
  275.         } else {
  276.             url = googleUrl+'search?q='+getQueryVariable('q')+'+site:'+wikipediaUrl+'wiki&btnI=I%27m+Feeling+Lucky';
  277.         }
  278.         retrieveURL(url);
  279.         //unsafeWindow.console.log(url);
  280.     }
  281.     
  282.     window.checkLoaded = function () {
  283.         if(articleLoaded==false) {
  284.             document.getElementById('wikibox').innerHTML = networkError;
  285.         }
  286.     }
  287.     wikibox.innerHTML = '<img id="throbber" src="'+Images.throbber+'" />' + getString('loadingArticlePleaseWait');
  288.     wikibox.id = 'wikibox';
  289.     wikibox.className = 'shrunk';
  290.  
  291.     //if(results[0]) {
  292.         results.parentNode.insertBefore(wikibox, results);
  293.     //}
  294. }
  295.  
  296. // Only show Wikibox if on first page, and not hidden
  297. if(GM_getValue('hidden', '0') == '0' && (start == '' || start == 0)) {
  298.     initWikibox();
  299. }
  300.  
  301. showGooglepediaBox.id = 'showGooglepediaBox';
  302. showGooglepediaBox.innerHTML = showGooglepedia;
  303.  
  304. //if(allParagraphs[0]) {
  305. results.parentNode.insertBefore(showGooglepediaBox, results);
  306. //}
  307.  
  308. document.getElementById('showLink').addEventListener("mousedown", function(e) {
  309.  
  310.     if(!document.getElementById('wikibox')) {
  311.         initWikibox();
  312.     }
  313.     
  314.     GM_setValue('hidden', '0');
  315.     
  316.     document.getElementById('showGooglepediaBox').style.display='none';
  317.     document.getElementById('wikibox').style.display='block';
  318. }, false);
  319.                 
  320. var brTags = document.getElementsByTagName('br')
  321. var doNextBr = false;
  322.  
  323. for (var i = 0; i < brTags.length; i++) {
  324.     if(brTags[i].getAttribute('clear') == 'all') {
  325.         brTags[i].setAttribute('clear', 'none');
  326.         i = brTags.length;
  327.     }
  328. }
  329.  
  330. if(document.getElementById('navbar')) {
  331.     document.getElementById('navbar').innerHTML = document.getElementById('navbar').innerHTML + '<br clear=all />';
  332. }
  333.